/*
* ============================================================================
*  Name        : sea_stack.cpp
*  Part of     : Finite state machine utilities
*  Description : 
*  Version     : %version: %
*  
*
* ============================================================================
*/
#include "sea_stack.h"

using namespace sea;

/**
 * @file sea_stack.cpp
 *
 * @ingroup AssociationUtilities
 */

// -------------------------------------------------------------------------------------------------
// Push element into the stack
// -------------------------------------------------------------------------------------------------
bool Stack::push( Object* obj )
{
    if ( !obj )
    {
        return false;
    }

    attach_first( obj );
    return true;
}

// -------------------------------------------------------------------------------------------------
// Pops element from the stack
// -------------------------------------------------------------------------------------------------
sea::ref< > Stack::pop( )
{
    if ( !size( ) )
    {
        return NULL;
    }
    sea::aref obj = get_first( );
    detach( obj.get( ) );

    // Dont return just obj!!!
    // Copy has to be done 1st - before local auto object 
    // gets destroyed
    return sea::ref< >( obj.get( ) );
}

// -------------------------------------------------------------------------------------------------
